package game.snake.direction;

import game.Field;
import game.Point;
import game.snake.Snake;
import game.snake.SnakeBody;

/**
 * The down direction of the snake.
 * 
 * @author Sarun Wongtanakarn 5510546166
 * @author Apiwat Jierakulpanit 5510546212
 * @Version 2013.05.01
 */
public class DirectionDown extends Direction {

	public DirectionDown(Snake snake) {
		super(snake);
	}

	@Override
	public void changeDirection(Direction direction) {
		if (!(direction instanceof DirectionUp))
			snake.setDirection(direction);
		snake.getHead().setDirection(direction);
	}

	@Override
	public void move(SnakeBody blockBody, Field field) {
		int newY = blockBody.getPoint().Y - 1;
		if(newY < 0 )
			newY = field.getHeight()-1 ;
		blockBody
				.setPoint(field.POINT[blockBody.getPoint().X][newY]);
	}

	@Override
	public void growth(Point[][] point) {
		snake.getBody().add(
				new SnakeBody(point[snake.getTail().getPoint().X][snake
						.getTail().getPoint().Y + 1], snake.getTail()
						.getDirection()));
	}

}
